var allComments = "",highComments = "",middleCommens = "",lowComments = "";
var allNum=0,highNum=0,middleNum=0,lowNum=0;

$(document).ready(function() {
	$(".dt-ifm-box3 input").val(0);
	var demoTrigger = document.querySelector('.goodPhoto');
	new Drift(demoTrigger,{
		paneContainer: document.querySelector('.goodPhotoContainer'),
		inlinePane: 900,
		inlineOffsetY: -85,
		containInline: true
	});

	$.ajax({
		url: ctx+"/shop/shopMessagePage.do?id="+$('[name="shopId"]').val(),
		dataType: 'html',
		success: function (document) {
			$('#shopMessage').html(document);
		}
	});

	/*商品详情 js*/
	$("[qie-xiao] li").hover(function() {
		$(this).addClass('current').siblings().removeClass('current');
		$("[qie-da] li").eq($(this).index()).show().siblings().hide();
	});

	var dtu=0;
	var xtu=0;
	var spend=1000;
	$(".dt-qie-right").click(function(event) {
		xtu++;
		if(xtu>3){
			xtu=0;
			$("[qie-xiao]").css("left",0);
		}
		$("[qie-xiao]").animate({"left":-xtu*72},spend);
	});
	$(".dt-qie-left").click(function(event) {
		xtu--;
		if(xtu<0){
			xtu=3;
			$("[qie-xiao]").css("left",-72);
		}
		$("[qie-xiao]").animate({"left":-xtu*72},spend);
	});
		/*内容-p-中间*/
	$(".dt-if-dd1 a").click(function(event) {
		$(this).addClass('current').siblings().removeClass("current");
	});

			/*内容切换*/
	$("[com-det]").click(function(event) {
		var dt = $(this).attr("com-det");
		$(this).addClass('current').siblings().removeClass("current");
		$("[com-det-show]").hide();
		$("[com-det-show="+dt+"]").show();
	});
			/*dt-if1-m*/
	$(".dt-ifm-box3 .box3-right").click(function(event) {
		var val = $(".dt-ifm-box3 input").val();
		if(parseInt(val)<parseInt($("#stock").val())){
			val++;
		}
		$(".dt-ifm-box3 input").val(val);
	});
	$(".dt-ifm-box3 .box3-left").click(function(event) {
		var val = $(".dt-ifm-box3 input").val();
		if(val>1){
			val--;
		}
		$(".dt-ifm-box3 input").val(val);
	});
	$(".dt-ifm-box3 input").on("change",function(){
		var val = parseInt($(".dt-ifm-box3 input").val());
		val = val?val:0;
		if(val>11)
			val=11;
		if(val<0)
			val=0;
		$(".dt-ifm-box3 input").val(val);
	});

	$.ajax({
		url: ctx+"/comment/list.do?goodId="+$('[name="goodId"]').val(),
		success: function (comments) {
			var comment;
			for(var i=0;i<comments.length;i++){
				allcomment =
					'<dl class="allCommentDL">' +
						'<dd>' +
							'<a style="color: #666;font-size:15px;">'+comments[i].name+'</a>' +
							'<p class="b3-p1" style="font-size:18px;padding-left: 40px;word-wrap: break-word;">'+comments[i].content+'</p>' +
							'<p class="b3-p2">'+new Date(comments[i].time).Format('yyyy-MM-dd hh:mm:ss')+'</p>' +
						'</dd>' +
						'<div style="clear:both;"></div>' +
					'</dl>';
				highcomment =
					'<dl class="highCommentDL">' +
					'<dd>' +
					'<a style="color: #666;font-size:15px;">'+comments[i].name+'</a>' +
					'<p class="b3-p1" style="font-size:18px;padding-left: 40px;word-wrap: break-word;">'+comments[i].content+'</p>' +
					'<p class="b3-p2">'+new Date(comments[i].time).Format('yyyy-MM-dd hh:mm:ss')+'</p>' +
					'</dd>' +
					'<div style="clear:both;"></div>' +
					'</dl>';
				middlecomment =
					'<dl class="middleCommentDL">' +
					'<dd>' +
					'<a style="color: #666;font-size:15px;">'+comments[i].name+'</a>' +
					'<p class="b3-p1" style="font-size:18px;padding-left: 40px;word-wrap: break-word;">'+comments[i].content+'</p>' +
					'<p class="b3-p2">'+new Date(comments[i].time).Format('yyyy-MM-dd hh:mm:ss')+'</p>' +
					'</dd>' +
					'<div style="clear:both;"></div>' +
					'</dl>';
				lowcomment =
					'<dl class="lowCommentDL">' +
					'<dd>' +
					'<a style="color: #666;font-size:15px;">'+comments[i].name+'</a>' +
					'<p class="b3-p1" style="font-size:18px;padding-left: 40px;word-wrap: break-word;">'+comments[i].content+'</p>' +
					'<p class="b3-p2">'+new Date(comments[i].time).Format('yyyy-MM-dd hh:mm:ss')+'</p>' +
					'</dd>' +
					'<div style="clear:both;"></div>' +
					'</dl>';
				allComments = allComments+allcomment;
				allNum++;
				if(comments[i].score<2){
					lowComments = lowComments+highcomment;
					lowNum++;
				}
				else if(comments[i].score<9){
					middleCommens = middleCommens+middlecomment;
					middleNum++;
				}
				else{
					highComments = highComments+lowcomment;
					highNum++;
				}
			}
			$("#commentDiv").append(allComments);
			$("#allTab").html('全部（'+allNum+'）').click(function(){
				$(".highCommentDL").remove();
				$(".middleCommentDL").remove();
				$(".lowCommentDL").remove();
				$(".allCommentDL").remove();
				$('.current-li').removeClass("current-li");
				$(this).addClass("current-li");
				$("#commentDiv").append(allComments);
			});
			$("#highTab").html('好评（'+highNum+'）').click(function(){
				$(".highCommentDL").remove();
				$(".middleCommentDL").remove();
				$(".lowCommentDL").remove();
				$(".allCommentDL").remove();
				$('.current-li').removeClass("current-li");
				$(this).addClass("current-li");
				$("#commentDiv").append(highComments);
			});
			$("#middleTab").html('中评（'+middleNum+'）').click(function(){
				$(".highCommentDL").remove();
				$(".middleCommentDL").remove();
				$(".lowCommentDL").remove();
				$(".allCommentDL").remove();
				$('.current-li').removeClass("current-li");
				$(this).addClass("current-li");
				$("#commentDiv").append(middleCommens);
			});
			$("#lowTab").html('差评（'+lowNum+'）').click(function(){
				$(".highCommentDL").remove();
				$(".middleCommentDL").remove();
				$(".lowCommentDL").remove();
				$(".allCommentDL").remove();
				$('.current-li').removeClass("current-li");
				$(this).addClass("current-li");
				$("#commentDiv").append(lowComments);
			});
		}
	});
});

Date.prototype.Format = function (fmt) { //author: meizz
	var o = {
		"M+": this.getMonth() + 1, //月份
		"d+": this.getDate(), //日
		"h+": this.getHours(), //小时
		"m+": this.getMinutes(), //分
		"s+": this.getSeconds(), //秒
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度
		"S": this.getMilliseconds() //毫秒
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}











